<?php

class MAIMember extends FTAObject {
		
		var $cmsDocument;
		
		function MAIMember(){
			parent::__construct();
				
			global $db;	
			$this->cmsDocument = new CmsDocument($db);
		}
		
		function getMembers(){
			$this->cmsDocument->flush();
			$this->cmsDocument->setActiveDocuments();
			$this->cmsDocument->addDocumentType('docMember');
			//$this->cmsDocument->sort("<<md.rank>>");
			$this->cmsDocument->setPageSize(null);
			$this->cmsDocument->setPageNumber(null);
			$this->cmsDocument->resetIterator();
			
			$allDocuments = $this->cmsDocument->getAllDocuments();
			
			if (!$allDocuments)
				$allDocuments = array();
				
			return $allDocuments;
			
		}
		
		function getMember($documentcode = null){
			if(is_null($documentcode))
				return false;
			$this->cmsDocument->flush();
			$this->cmsDocument->setActiveDocuments();
			$this->cmsDocument->addDocumentType('docMember');
			
			if (is_numeric( ($documentcode * 1) ) &&  0 < ($documentcode * 1)){
				$this->cmsDocument->addConstraint('documentcode',$documentcode);	
			} else {
				$this->cmsDocument->addConstraint('<<title>>',$documentcode);
			}
			
			$this->cmsDocument->setPageSize(1);
			$this->cmsDocument->resetIterator();
			
			if($this->cmsDocument->totalDocuments() == 1) {
				return $this->cmsDocument->nextDocumentFromCache();
			} else {
				return false;
			}
			
		}
		
		function renderMembersSelect($productId = null){
			$members = $this->getMembers();
			if(is_null($members))
				return;
				
					foreach($members as $member){
?>
	                 <option value="<?php echo $member->documentcode; ?>" <?php 
	                 if($member->documentcode == $productId){
	                 	echo " selected ";
	                 }
	                 ?> ><?php echo $member->title; ?></option>
<?
					}
														
		}
		
		
		
		
}


	function mai_getMembersSelect($productId = null) {
		ob_start();
		$maiObject = mai_getSharedMemberObject();	
		$maiObject->renderMembersSelect($productId);
		return ob_get_clean();			
	}

	function mai_getSharedMemberObject(){

		global $fta_;

		global $MAIMemberClass;
		
		if(!is_null($MAIMemberClass) && "MAIMember" != $MAIMemberClass){
		} else {
			$MAIMemberClass = "MAIMember";
		}
			
		if (!array_key_exists('maiMember',$fta_)){
			$fta_->maiMember = new  $MAIMemberClass();
		}
		return $fta_->maiMember;
	}


?>